#ifndef TV_PNG_H
#define TV_PNG_H

// This implements a simple and fast PNG encoder https://w3.org/TR/png/

#include <stdint.h>
#include <unistd.h>

namespace tv {
class Framebuffer;

namespace png {
// Encode framebuffer as PNG into given buffer and return encoded size.
//
// Provided buffer needs to be large enough; use UpperSizeEstimate() to prepare.
//
// "compression_level" is the compression level; 0 means essentially plain
// bytes without compression, 1 and more compresses. For our use-case probably
// only 1 is ever needed (we want to be fast).
//
// The ColorEncoding enum requests if 24Bit RGB or full 32Bit RGBA is encoded.
enum class ColorEncoding {
  kRGBA_32,
  kRGB_24,
};
size_t Encode(const Framebuffer &fb, int compression_level,
              ColorEncoding encoding, char *buffer, size_t size);

// Return estimate of maximum size needed to encode image of given size.
size_t UpperBound(int width, int height);

} // namespace png
} // namespace tv
#endif // TV_PNG_H
